import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
import '../widgets/preview/file_preview_widget.dart';

class FilePreviewPage extends StatefulWidget {
  final int fileId;
  final String fileName;
  final String fileType;

  const FilePreviewPage({
    super.key,
    required this.fileId,
    required this.fileName,
    required this.fileType,
  });

  @override
  State<FilePreviewPage> createState() => _FilePreviewPageState();
}

class _FilePreviewPageState extends State<FilePreviewPage> {
  final GlobalKey<FilePreviewWidgetState> _previewKey =
      GlobalKey<FilePreviewWidgetState>();

  void _refreshPreview() {
    _previewKey.currentState?.reloadPreview(forceRefresh: true);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.fileName, style: const TextStyle(fontSize: 16)),
        actions: [
          // 刷新按钮
          IconButton(
            icon: const Icon(Icons.refresh),
            tooltip: '刷新预览',
            onPressed: _refreshPreview,
          ),
          // 下载按钮
          IconButton(
            icon: const Icon(Icons.download),
            tooltip: '下载文件',
            onPressed: () {
              // 下载功能由各预览组件内部实现
            },
          ),
        ],
      ),
      body: FilePreviewWidget(
        key: _previewKey,
        fileId: widget.fileId,
        fileName: widget.fileName,
        fileType: widget.fileType,
      ),
    );
  }
}
